﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyRead.API.Appicant.Command.MenuCommand;
using B.S.DataBase.MyRead.API.DTOs;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyRead.API.Controllers
{
    /// <summary>
    /// 菜单管理模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenuController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 菜单列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<MenuDTOs>>> GetMenuList([FromQuery] GetMenuCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 菜单名称唯一验证
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public async Task<APIResult<string>> OnenessMenuName([FromQuery] OnenessMenuNameCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 反填查询菜单对象
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<MenuModel>>> GetMenuName([FromQuery]GetMenuNameCommand request, CancellationToken cancellationToken)
        { 
            return await mediator.Send(request);
        }

        /// <summary>
        /// 判断删除的菜单是否父级
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        [HttpGet]
        public async Task<APIResult<List<MenuModel>>> DeleteMenuJudge([FromQuery]DeleteMenuJudgeCommand request )
        { 
            return await mediator.Send(request);
        }


        /// <summary>
        /// 递归显示菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<TreeMenuDTOs>>> GetTreeMenu([FromQuery]GetTreeMenuCommand request, CancellationToken cancellationToken)
        { 
            return mediator.Send(request);
        }


    }
}
